package com.cy.pj.goods.service.impl;

import com.cy.pj.common.annotation.ClearCache;
import com.cy.pj.common.annotation.RequiredCache;
import com.cy.pj.goods.dao.GoodsDao;
import com.cy.pj.goods.pojo.Goods;
import com.cy.pj.goods.service.GoodsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Cx
 * @stage secondStageOfWeb
 * @creat 2020-11-04 20:09
 */
@Slf4j
@Service
public class GoodsServiceImpl implements GoodsService {

//    private static final Logger log = LoggerFactory.getLogger(GoodsServiceImpl.class);

    @Autowired(required = false)
    private GoodsDao goodsDao;

    @RequiredCache
    @Override
    public List<Goods> findGoods() {
        return goodsDao.findGoods();
    }

    @RequiredCache
    @Override
    public List<Goods> findGoodsByName(String name) {
        long start = System.currentTimeMillis();
        List<Goods> list = goodsDao.findGoodsByName(name);
        long end = System.currentTimeMillis();
        log.info("findGoodsByName->time->{}", (end - start));
        return list;
    }

    @ClearCache
    @Override
    public int deleteById(Integer id) {
        int rows = goodsDao.deleteById(id);
        return rows;
    }

    @ClearCache
    @Override
    public int saveGoods(Goods entity) {
        int rows = goodsDao.insertObject(entity);
        return rows;
    }

    @RequiredCache
    @Override
    public Goods findById(Integer id) {
        return goodsDao.findById(id);
    }
    @ClearCache
    @Override
    public int updateGoods(Goods goods) {
        return goodsDao.updateGoods(goods);
    }

}
